package com.cnunicom.common.utils;

import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.api.impl.WxMpServiceImpl;
import me.chanjar.weixin.mp.config.WxMpConfigStorage;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;


/**
 * @Author: dingziyuan
 * @Date: 2020/2/5/005 8:52
 * @Description: 定时器获取access_token
 */
@Component
public class AccessTokenUtil {

    @Resource
    private WxMpService wxMpService;

    //    @Scheduled(cron = "0/2 * * * * *")
    public void getToken() throws WxErrorException {

        final WxMpConfigStorage storage = wxMpService.getWxMpConfigStorage();
        if (wxMpService.switchover(Constant.mpMessage.SUBSCRIBE_APP_ID.getValue())) {
            String accessToken = wxMpService.getAccessToken();
            System.out.println(accessToken);
        }
    }

}
